package com.ruoyi.web.core.config;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * jedis连接池配置类
 */
@Configuration
public class JedisConfig {
    private final Log log = LogFactory.getLog(this.getClass());

    @Value("${spring.redis.host}")
    private String host;//ip
    @Value("${spring.redis.port}")
    private int port;//端口
    @Value("${spring.redis.password}")
    private String password;//连接密码
    @Value("${spring.redis.timeout}")
    private int timeout;//超时时间
    @Value("${spring.redis.jedis.pool.max-active}")
    private int maxActive;//连接数
    @Value("${spring.redis.jedis.pool.max-idle}")
    private int maxIdle;//最大空闲数
    @Value("${spring.redis.jedis.pool.min-idle}")
    private int minIdle;//最小空闲数

    @Bean
    public JedisPool jedisPool() {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPoolConfig.setMinIdle(minIdle);
        jedisPoolConfig.setMaxTotal(maxActive);

        JedisPool jedisPool = new JedisPool(jedisPoolConfig,host,port,timeout,password);
        log.info("JedisPool连接成功:"+host +"\t"+port);
        return jedisPool;
    }
}
